# -*- coding: utf-8 -*-            
# @Author : chenliang
# @Time : 2024/1/18 14:06

from Case.python_ui.Common.basepage import Basepage
from Case.python_ui.PageLocate.user_product_computing_locator import ProductComputingLocator
from Case.python_ui.PageLocate.user_product_ack_locator import ProductackLocator
from Case.python_ui.Test_data.menu_name_data import MenuName
import random
from Case.python_ui.PageLocate.product_management_locator import ProductManagementLocator
from Case.python_ui.Pageobject.admin_product_managent_pages import ProductManagementPages

import time


class Productack(Basepage):

    # 根据tab菜单名称进行点击
    def click_my_resource_tab(self, tab_name):
        doc = '根据my resource页的tab菜单名字进行点击进入'
        time.sleep(5)
        self.wait_elevisble(ProductComputingLocator.my_resource_tab_list, doc)
        my_resource_tab_list = self.get_elements(ProductComputingLocator.my_resource_tab_list, doc)
        for i in my_resource_tab_list:
            print('*****:', i.text, type(i))
            if i.text == tab_name:
                print('++++:', i.text)
                i.click()
        time.sleep(2)

    # 根据产品名称进行点击
    def get_product_name_to_click(self, product_name):
        doc = '根据产品名称然后点击'
        prod_list = self.get_elements(ProductComputingLocator.my_resource_product_list, doc)
        time.sleep(2)
        for prod in prod_list:
            print('+++++:', prod.text)
            if prod.text == product_name:
                prod.click()
                break
        time.sleep(5)

    # tab页根据产品名称进行点击进入控制台
    def click_product_by_name(self, product_name):
        doc = 'tab页根据产品名称进行点击进入控制台'
        time.sleep(5)
        self.wait_elevisble(ProductComputingLocator.move_computing_create_new, doc)
        self.move_mouse_to_element(ProductComputingLocator.move_computing_create_new)
        time.sleep(2)
        self.get_product_name_to_click(product_name)
        time.sleep(2)


    # 进入Container Service for Kubernetes管理控制页
    def enter_Container_Service_Kubernetes(self, cmdopt):
        doc = 'Container Service Kubernetes 页面管理控制页'
        self.click_my_resource_tab(MenuName.compute_name[cmdopt])
        self.click_product_by_name('Container Service for Kubernetes')
        for i in range(3):
            try:
                self.wait_elevisble(ProductackLocator.iframe_Container_Service, doc)
                self.driver.switch_to.frame(self.get_element(ProductackLocator.iframe_Container_Service, doc))
                self.wait_elevisble(ProductackLocator.if_enter_Container_Service_Kubernetes, doc)
                if self.get_element(ProductackLocator.if_enter_Container_Service_Kubernetes, doc).text == 'Container Service':
                    break
            except:
                continue
        time.sleep(10)
        self.wait_elevisble(ProductackLocator.if_enter_Container_Service_Kubernetes, doc)
        print("iframe++++:",self.get_element(ProductackLocator.if_enter_Container_Service_Kubernetes, doc).text)
        #print("+++:", self.get_element(ProductBlockStorgeLocator.if_enter_block_storage_page, doc).text)
        assert self.get_element(ProductackLocator.if_enter_Container_Service_Kubernetes, doc).text == 'Container Service'
        time.sleep(5)



    # DBS 页面管理控制页
    def enter_database_backup(self, cmdopt):
        doc = 'DBS 页面管理控制页'
        self.click_my_resource_tab('Database')
        self.click_product_by_name('Database Backup')
        for i in range(3):
            try:
                self.wait_elevisble(ProductackLocator.iframe_Container_Service, doc)
                self.driver.switch_to.frame(self.get_element(ProductackLocator.iframe_Container_Service, doc))
                self.wait_elevisble(ProductackLocator.if_enter_database_backup, doc)
                if self.get_element(ProductackLocator.if_enter_database_backup, doc).text == 'Database Backup':
                    break
            except:
                continue
        time.sleep(10)
        self.wait_elevisble(ProductackLocator.if_enter_database_backup, doc)
        print("iframe++++:",self.get_element(ProductackLocator.if_enter_database_backup, doc).text)
        #print("+++:", self.get_element(ProductBlockStorgeLocator.if_enter_block_storage_page, doc).text)
        assert self.get_element(ProductackLocator.if_enter_database_backup, doc).text == 'Database Backup'
        time.sleep(5)

    # HBR 页面管理控制页
    def enter_hbr(self, cmdopt):
        doc = 'HBR 页面管理控制页'
        self.click_my_resource_tab('Developer Services')
        self.click_product_by_name('Hybrid Backup Recovery')
        for i in range(3):
            try:
                self.wait_elevisble(ProductackLocator.iframe_Container_Service, doc)
                self.driver.switch_to.frame(self.get_element(ProductackLocator.iframe_Container_Service, doc))
                self.wait_elevisble(ProductackLocator.if_enter_hbr, doc)
                if self.get_element(ProductackLocator.if_enter_hbr, doc).text == 'ASR for Backup and Recovery':
                    break
            except:
                continue
        time.sleep(10)
        self.wait_elevisble(ProductackLocator.if_enter_hbr, doc)
        print("iframe++++:",self.get_element(ProductackLocator.if_enter_hbr, doc).text)
        #print("+++:", self.get_element(ProductBlockStorgeLocator.if_enter_block_storage_page, doc).text)
        assert self.get_element(ProductackLocator.if_enter_hbr, doc).text == 'ASR for Backup and Recovery'
        time.sleep(5)










